home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / appl / napsaterm / dispmacros.h < prev    next >
C/C++ Source or Header  |  1994-05-14  |  6KB  |  164 lines

  1. /* dispmacros.h --- display macros for niftyterm
  2.  *
  3.  * Copyright 1989, Chris Newman
  4.  * All Rights Reserved
  5.  * Permission is granted ot copy, modify, and use this as long
  6.  * as this notice remains intact.  This is a nifty program.
  7.  *
  8.  * $Author: ppessi $ $Revision: 2.0 $ $Date: 1993/11/15 03:30:07 $
  9.  */
  10.  
  11. #define MAXWIDTH    132
  12. #define    MINWIDTH    40
  13. #define MAXHEIGHT    75
  14. #define    MINHEIGHT    2
  15.  
  16. /* This data structure should not need changing for different displays
  17.  * format of buffers:
  18.  * disp.sbuf -- x*(y+1) array of line styles
  19.  *    first byte in disp.sbuf line: OR of all styles on line
  20.  *        -- if 0, then no styles, if -1, unused
  21.  */
  22. extern struct nifty_display {
  23.     int        curx;            /* cursor location  [0,winwidth),[0,winwinheight) */
  24.     int        cury;
  25.     int        savex;            /* save of cursor position */
  26.     int        savey;
  27.     int        winwidth;            /* window size: columns, rows */
  28.     int        winheight;
  29.     int        maxwidth;            /* width of the buffer */
  30.     int        maxheight;            /* height of the buffer */
  31.     int        bufwidth;            /* width of buffer (maxwidth+1) */
  32.     int        scrolltop;            /* top of scrolling region */
  33.     int        scrollbot;            /* bottom of scrolling region */
  34.     int        scrollskip;            /* amount to jump scroll */
  35.     int        scrolldefault;        /* default scroll skip */
  36.     short   style;            /* current display style */
  37.     short   savestyle;            /* save the display style */
  38.     int        invert;            /* invert the screen */
  39.     int        insert;            /* insert mode */
  40.     int        origin;            /* origin mode -- if 1, origin at scrolltop */
  41.     int        wrap;            /* 0=stop at margin, 1=wrap at margin */
  42.     int        visual;            /* 0=underline cursor, 1=block cursor,
  43.                          2 = invisible cursor */
  44.     int     blink;                      /* 0=no blink, 1=blinking cursor */
  45.     char    *plines[MAXHEIGHT];        /* array of line pointers (faster scrolling) */
  46.     short   *pstyles[MAXHEIGHT];    /* array of style pointers (faster scrolling) */
  47.     char    *buf;            /* malloc text buffer */
  48.     short   *sbuf;            /* malloc styles buffer */
  49.     char    *tabstops;            /* malloc flag buffer */
  50. } disp;
  51.  
  52. /* cursor visual attributes */
  53. #define CUR_UNDERLINE    0x00
  54. #define CUR_BLOCK    0x01
  55. #define CUR_INVISIBLE    0x02
  56. #define CUR_BOX        0x04
  57. #define CUR_NOBLINK     0x00
  58. #define CUR_BLINK       0x01
  59.  
  60. /* attributes */
  61. #define    UNDERLINE    (0x0001)
  62. #define    BOLD        (0x0002)
  63. #define    ITALIC        (0x0004)
  64. #define    DOUBLE1        (0x0008)
  65. #define    DOUBLE2        (0x0010)
  66. #define    ALTERNATE    (0x0020)
  67. #define    INVERSE        (0x0040)
  68. #define    FLASH        (0x0080)
  69. #define    BLANK        (0x0100)
  70. #define    HALFBRITE    (0x0200)
  71. #define    DOUBLE_MASK    (DOUBLE1 | DOUBLE2)
  72.  
  73. /* marcos to access data structure */
  74. #define    STYLEFLAG(y)    (disp.pstyles[y][disp.maxwidth])
  75. #define    LINELENST(y)    (disp.plines[y][disp.maxwidth])
  76. #define    LINELEN(y)    ((unsigned char) LINELENST(y))
  77. #define    STYLELINE(y)    (disp.pstyles[y])
  78. #define    TEXTLINE(y)    (disp.plines[y])
  79. #define    TEXTPOS(x, y)    (disp.plines[y][x])
  80. #define    STYLEPOS(x, y)    (disp.pstyles[y][x])
  81.  
  82. /* macros to operate on the display */
  83. #define    NEWLINE()    if (++disp.cury > disp.scrollbot) {disp.cury-=disp.scrollskip; dsscroll(disp.scrolltop, disp.scrollbot - disp.scrolltop + 1, disp.scrollskip);}
  84.  
  85. #define DSTEST(c, style)  /* fill screen with character c, style s */\
  86. {                                        \
  87.     register int tx, ty;                            \
  88.     for    (ty = 0; ty < disp.winheight; ty++) {                    \
  89.     LINELENST(ty) = disp.winwidth-1;                    \
  90.     STYLEFLAG(ty) = style;                            \
  91.     for (tx    = 0; tx    < disp.winwidth; tx++)                    \
  92.         TEXTPOS(tx,    ty) = (c), STYLEPOS(tx,    ty) = (style);            \
  93.     }                                        \
  94. }
  95.  
  96. #define    DSCLEAR(x,y,x1,y1)    /* quickly clear out the interal storage */\
  97. {                                        \
  98.     register int tempx,    tempy;                            \
  99.     int    linelen;                                \
  100.     for    (tempy = y; tempy <= y1; tempy++) {                    \
  101.     if (x >    (linelen = LINELEN(tempy)))                    \
  102.         continue;                                \
  103.     if (x1 > linelen) {                            \
  104.         LINELENST(tempy) = linelen = x;                    \
  105.     } else                                    \
  106.         for    (tempx = x; tempx <= x1; tempx++)                \
  107.         TEXTPOS(tempx, tempy) =    ' ', STYLEPOS(tempx, tempy) = 0;    \
  108.     STYLEFLAG(tempy) &= DOUBLE_MASK;                    \
  109.     for (tempx = 0;    tempx <= linelen;tempx++)                \
  110.         STYLEFLAG(tempy) |=    STYLEPOS(tempx,    tempy);                \
  111.     }                                        \
  112. }
  113.  
  114. /* clip cursor position, clip lines, and recalculate styles */
  115. #define    DSRESIZE() {\
  116.     register int x, y;\
  117.     int    linelen;\
  118.     SLIMITCK(disp.curx,    disp.winwidth);\
  119.     SLIMITCK(disp.cury,    disp.winheight);\
  120.     for (y = 0; y < disp.winheight; y++) {\
  121.     if (disp.winwidth < (linelen=LINELEN(y)))\
  122.     LINELENST(y) = linelen = disp.winwidth;\
  123.     for (style = STYLEFLAG(y) & DOUBLE_MASK, x = 0;\
  124.     x < disp.winwidth && x < linelen; x++)\
  125.     style |= STYLEPOS(x,y);\
  126.     STYLEFLAG(y) = style;\
  127.     }\
  128.     SLIMITCK(disp.scrollbot,disp.winheight);\
  129.     if (disp.scrolltop >= disp.scrollbot-1)\
  130.     disp.scrolltop = 0;\
  131. }
  132.  
  133. #define    DSSCROLL(y, amount, numlines)\
  134. if(ABS(amount)<(numlines)) {\
  135. char *templ;\
  136. short *templs;\
  137. int i, maxy;\
  138. if(amount>0) {\
  139. for(i=y,maxy=y+numlines-amount;i<maxy;i++){\
  140. templ=disp.plines[i],templs=disp.pstyles[i];\
  141. disp.plines[i]=disp.plines[i+amount];\
  142. disp.pstyles[i]=disp.pstyles[i+amount];\
  143. disp.plines[i+amount]=templ,disp.pstyles[i+amount]=templs;\
  144. }\
  145. }\
  146. else {\
  147. for(i=y+numlines-1,maxy=y-amount;i>=maxy;i--){\
  148. templ=disp.plines[i],templs=disp.pstyles[i];\
  149. disp.plines[i]=disp.plines[i+amount];\
  150. disp.pstyles[i]=disp.pstyles[i+amount];\
  151. disp.plines[i+amount]=templ,disp.pstyles[i+amount]=templs;\
  152. }\
  153. }\
  154. }
  155.  
  156. #define    DSEMPTYLINE(top, bottom)    /* empty lines from top to bottom-1 */\
  157. {                                        \
  158.     register int i;                                \
  159.     for    (i = top; i < bottom; i++)                        \
  160.     LINELENST(i) = STYLEFLAG(i) = 0;                    \
  161. }
  162.  
  163.  
  164.